package com.leadership.training.entity.project;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;


/**
 * 项目-期
 * @author Rockett
 *
 */
@Entity
@Table(name = "t_project_phase")
public class ProjectPhase {
    
    /**
     * ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     * 所属项目
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Project project;
    
    /**
     * 当前期数
     */
    private int phase;
    /**
     * 开始日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date beginDate;

    /** 
     * 结束日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
   private Date endDate;
    /**
     * 是否可用
     */
    @Column(name = "is_disabled")
    private boolean disabled;

    /**
     * 状态
     */
    private String status;
    /**
     * 评估结果
     */
    private String surveyResult;
    /**
     * 评估建议
     */
    private String surveySuggestion;

    /**
     * 是否结业期 ‘是’、‘否’   冗余字段 报表导出用
     */
    private String lastPhase;

    /**
     * The default constructor
     */
    public ProjectPhase() {
        this.disabled=false;
    }
    
    public ProjectPhase(ProjectPhase oldProjectPhase) {
        this.phase = oldProjectPhase.getPhase();
        this.beginDate = oldProjectPhase.getBeginDate();
        this.endDate = oldProjectPhase.endDate;
        this.disabled = false;
        
    }
    
    /**
     * @return
     */
    public ProjectPhase editDisabled() {
        this.disabled = true;
        return this;
    }
    
    /**
     * @param project
     * @param phase
     * @return
     */
    public ProjectPhase init(Project project, int phase) {
        this.project = project;
        this.phase = phase;
        return this;
    }
    
    /**
     * @param startDate
     * @param endDate
     * @return
     */
    public ProjectPhase editDate(Date startDate, Date endDate) {
        
        this.beginDate = startDate;
        
        this.endDate = endDate;
        
        return this;
    }
    
    /**
     * 
     * @return
     */
    public ProjectPhase delete() {
        this.disabled = true;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public String getSurveySocre() {
        if(org.apache.commons.lang3.StringUtils.isNotBlank(this.surveyResult)) {
            BigDecimal bd=new BigDecimal(this.surveyResult);
            double d1=bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
            return String.valueOf(d1);
        }else {
            return null;
        }
    }
    
    public boolean isDisabled() {
         return disabled;
     }


     public void setDisabled(boolean disabled) {
         this.disabled = disabled;
     }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }


    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }




    /**
     * @return the beginDate
     */
    public Date getBeginDate() {
        return beginDate;
    }

    /**
     * @return the project
     */
    public Project getProject() {
        return project;
    }


    /**
     * @param project the project to set
     */
    public void setProject(Project project) {
        this.project = project;
    }


    /**
     * @return the phase
     */
    public int getPhase() {
        return phase;
    }


    /**
     * @param phase the phase to set
     */
    public void setPhase(int phase) {
        this.phase = phase;
    }


    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }


    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }



    /**
     * @param beginDate the beginDate to set
     */
    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }


    /**
     * @return the surveyResult
     */
    public String getSurveyResult() {
        return surveyResult;
    }


    /**
     * @param surveyResult the surveyResult to set
     */
    public void setSurveyResult(String surveyResult) {
        this.surveyResult = surveyResult;
    }


    /**
     * @return the surveySuggestion
     */
    public String getSurveySuggestion() {
        return surveySuggestion;
    }


    /**
     * @param surveySuggestion the surveySuggestion to set
     */
    public void setSurveySuggestion(String surveySuggestion) {
        this.surveySuggestion = surveySuggestion;
    }

    /**
     * @return the lastPhase
     */
    public String getLastPhase() {
        return lastPhase;
    }

    /**
     * @param lastPhase the lastPhase to set
     */
    public void setLastPhase(String lastPhase) {
        this.lastPhase = lastPhase;
    }

}